<%@ page language="java" contentType="text/html; charset=utf-8"%>
     <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"  %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<meta name="renderer" content="webkit|ie-comp|ie-stand">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
<link rel="Bookmark" href="/favicon.ico" >
<link rel="Shortcut Icon" href="/favicon.ico" />
<!--[if lt IE 9]>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/html5shiv.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/respond.min.js"></script>
<![endif]-->
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui/css/H-ui.min.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/css/H-ui.admin.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/lib/Hui-iconfont/1.0.8/iconfont.css" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/skin/default/skin.css" id="skin" />
<link rel="stylesheet" type="text/css" href="<%=path%>/static/managecss/h-ui.admin/css/style.css" />
<script type="text/javascript" src="<%=path%>/static/js/jquery-3.2.1.js"></script>
<!-- 页码样式 -->
<style type="text/css">
	#paging a{
		border: 1px solid #ccc;
	    cursor: pointer;
	    display: inline-block;
	    margin-left: 2px;
	    text-align: center;
	    text-decoration: none;
	    color: #666;
	    height: 26px;
	    line-height: 26px;
	    text-decoration: none;
	    margin: 0 0 5px 5px;
	    padding: 0 10px;
		font-size: 14px; 
		position: relative;
	}
	
</style>
<title>管理员列表</title>
</head>
<body>
<c:set var="pageNum" value="${requestScope.admins.pageNum}"></c:set>

<nav class="breadcrumb"><i class="Hui-iconfont">&#xe67f;</i> 首页${requestScope.msg} <span class="c-gray en">&gt;</span> 管理员管理 <span class="c-gray en">&gt;</span> 管理员列表 <a class="btn btn-success radius r" style="line-height:1.6em;margin-top:3px" href="javascript:location.replace(location.href);" title="刷新" ><i class="Hui-iconfont">&#xe68f;</i></a></nav>
<div class="page-container">

	
	<div class="cl pd-5 bg-1 bk-gray mt-20"> <span class="l"><a href="javascript:;" onclick="datadel(this)"  class="btn btn-danger radius"><i class="Hui-iconfont">&#xe6e2;</i> 批量停用</a> 
	<a href="<%=path%>/manager/admin/adminAdd" onClick="changePass()" class="btn btn-primary radius">添加管理员</a></span> 
	<!-- onclick="admin_add('添加管理员','<%=path %>/manager/admin/adminAdd','800','500')" -->
	<!-- <span class="r">共有数据：<strong>54</strong> 条</span>  -->
	</div>
	<div class="mt-20">
	<table class="table table-border table-bordered table-bg table-sort"> 
		<thead>
			<tr>
				<th scope="col" colspan="9">管理员列表</th>
			</tr>
			<tr class="text-c">
				<th width="25"><input type="checkbox" name="allCheck" id="allCheck" value=""></th>
				<th width="40">ID</th>
				<th width="150">登录名</th>
				<th>权限</th>
				<th width="100">是否已启用</th>
				<th width="100">操作</th>
			</tr>
		</thead>
		<c:forEach items="${requestScope.admins.list }" var="admin" varStatus="stat">
		<c:if test="${admin.id != sessionScope.admin.id}">
	<tr class="text-c">
	
				<td><input type="checkbox" value="${admin.id }" name="sonBox"></td>
				<td>${stat.count}</td>
				<td>${admin.name }</td>
				<c:if test="${admin.isSuper}">
				<td id="super${admin.id}">超级管理员</td>
				</c:if>
				<c:if test="${!admin.isSuper}">
				<td id="super${admin.id}">普通管理员</td>
				</c:if>
				
				<c:if test="${admin.enable}" >
				<td class="td-status"><span class="label label-success radius">已启用</span></td>
				</c:if>
				<c:if test="${!admin.enable}">
				<td class="td-status"><span class="label label-warning radius">已停用</span></td>
				</c:if>
				
				<td class="td-manage">
				<c:if test="${admin.enable}">
				<c:if test="${admin.isSuper}">
					<c:if test="${requestScope.superCount > 2}">	
				<a style="text-decoration:none" onClick="admin_down(this,${admin.id})" class="super" href="javascript:;" title="减权"><i class="Hui-iconfont"  id="black">&#xe6ff;</i></a> 
					</c:if>
				</c:if>
				
				<c:if test="${!admin.isSuper}">		
						<c:if test="${requestScope.superCount < 5}">																				
				<a style="text-decoration:none" onClick="admin_up(this,${admin.id})" href="javascript:;" title="加权"><i class="Hui-iconfont" id="white">&#xe702;</i></a> 
						</c:if>
				</c:if>
				</c:if>
			    <c:if test="${admin.enable}" >
				<a style="text-decoration:none" onClick="admin_stop(this,${admin.id})" href="javascript:;" title="停用"><i class="Hui-iconfont">&#xe631;</i></a> 
				</c:if>
				<c:if test="${!admin.enable}" >
				<a style="text-decoration:none" onClick="admin_start(this,${admin.id},${admin.isSuper})" href="javascript:;" title="启用"><i class="Hui-iconfont">&#xe615;</i></a>
				</c:if>
				</td>
			</tr>	
</c:if>				
			
			</c:forEach>
			
	</table>
	
	</div>
</div>

<!-- 分页开始 -->
	<div id="paging" style="padding-left:550px;margin-top:30px;margin-bottom:100px;">
		<a id="first" style="width:35px;" href="<%=path%>/manager/admin/adminSuperList?pageNum=1">首页</a>
		<a id="prev" style="width:50px;">上一页</a>
		<c:forEach items="${requestScope.admins.navigatepageNums }" var="page">
		<a id="page${page }" href="<%=path%>/manager/admin/adminSuperList?pageNum=${page}">${page}</a>
		</c:forEach>
		<a id="next" style="width:50px; " href="javaScript:void(0)">下一页</a>&nbsp;
		<a id="last" style="width:35px; " href="<%=path%>/manager/admin/adminSuperList?pageNum=${requestScope.admins.pages}">尾页</a>
		<span>共${requestScope.admins.pages}页</span>&nbsp;&nbsp;
		<span>共&nbsp;${requestScope.admins.total}&nbsp;条数据</span>
	</div>
</div>	
<!-- 分页结束 -->	

<!--_footer 作为公共模版分离出去-->
<script type="text/javascript" src="<%=path%>/static/managecss/lib/jquery/1.9.1/jquery.min.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/lib/layer/2.4/layer.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/h-ui/js/H-ui.min.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/h-ui.admin/js/H-ui.admin.js"></script>
<!--/_footer 作为公共模版分离出去-->

<!--请在下方写此页面业务相关的脚本-->
<script type="text/javascript" src="<%=path%>/static/managecss/lib/zTree/v3/js/jquery.ztree.all-3.5.min.js"></script>
<script type="text/javascript" src="<%=path%>/static/managecss/lib/My97DatePicker/4.8/WdatePicker.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/lib/datatables/1.10.0/jquery.dataTables.min.js"></script> 
<script type="text/javascript" src="<%=path%>/static/managecss/lib/laypage/1.2/laypage.js"></script>

<script type="text/javascript">

var superCount = ${requestScope.superCount};

$(function() {
	 $("#allCheck").click(function() {
		  
		  if($("#allCheck").prop("checked")){
					$("input[type=checkbox]").prop("checked",true);
			}else{
					$("input[type=checkbox]").prop("checked",false);
			}
	});
});

/*管理员-增加
function admin_add(title,url,w,h){
	layer_show(title,url,w,h);
}*/
function admin_add(){
	layer.open({
		type: 1,
		area: ['300px','200px'],
		fix: false, //不固定
		maxmin: true,
		shade:0.4,
		title: '查看信息',
		content: '<div>管理员信息</div>'
	});
}
/*管理员-删除*/
function admin_del(obj,id){
	layer.confirm('确认要删除吗？',function(index){
		$.ajax({
			type: 'POST',
			url: '<%=path%>/manager/deleteAdmin',
			data:{id:id},
			dataType: 'json',
			success: function(data){
				$(obj).parents("tr").remove();
				layer.msg('已删除!',{icon:1,time:1000});
			},
			error:function(data) {
				console.log(data.msg);
			},
		});		
	});
}

//多选停用
function datadel(obj){
	var ids="";
	$("input[name=sonBox]:checked").each(function(){
       ids = ids + $(this).val()+",";
  });
	if(ids!=""){
		 layer.confirm('确认要停用吗？',function(index){
			$.ajax({
				type: 'POST',
				url: '<%=path%>/manager/admin/deleteAdmins',			
				data:{ids:ids},
				success: function(data){
					$(obj).parents("tr").remove();
					layer.msg('已停用!',{icon:1,time:1000});
					location.href = location.href;
				},
				error:function(data) {
					console.log(data.msg);
				},
			});		
		}); 
}else{
	alert("请先选择")
}
}	

/*管理员-编辑*/
function admin_edit(title,url,id,w,h){
	layer_show(title,url,w,h);
}
/*管理员-停用*/
function admin_stop(obj,id){
	layer.confirm('确认要停用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		 $.ajax({
            type: 'post',
            url: '<%=path %>/manager/admin/deleteAdmin',
            data:{id:id},
            //dataType: 'json',
            success: function(data){
      var x = $(obj).parents("tr");       	
  	x.find(".td-manage").empty();   
		x.find(".td-manage").append('<a onClick="admin_start(this,'+id+')" href="javascript:;" title="启用" style="text-decoration:none"><i class="Hui-iconfont">&#xe615;</i></a>');
		x.find(".td-status").html('<span class="label label-warning radius">已停用</span>');
		
		layer.msg('已停用!',{icon: 5,time:1000});
            },
            
        });    

	});
}

/*管理员-启用*/
function admin_start(obj,id,isSuper){
	
	layer.confirm('确认要启用吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
            type: 'post',
            url: '<%=path %>/manager/admin/reAddAdmin',
            data:{id:id},
            //dataType: 'json',
            success: function(data){
    if(isSuper){
				$(obj).parents("tr").find(".td-manage").prepend('<a  onClick="admin_down(this,'+id+')" href="javascript:;" title="减权" style="text-decoration:none">&nbsp;<i  class="Hui-iconfont" id=\"black\">&#xe6ff;</i></a>');
    }else{
				$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_up(this,'+id+')" href="javascript:;" title="加权" style="text-decoration:none"><i class="Hui-iconfont" id=\"white\">&#xe702;</i></a>');
    }        	
		$(obj).parents("tr").find(".td-manage").append('<a onClick="admin_stop(this,'+id+')" href="javascript:;" title="停用" style="text-decoration:none;"><i class="Hui-iconfont">&#xe631;</i></a>');

		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
		$(obj).remove();
		layer.msg('已启用!', {icon: 6,time:1000});
		
            },
            
        });    
	});
}

/*管理员-加权限*/
function admin_up(obj,id){
	//alert(superCount);
	if(superCount>=5) {
		alert("不能再加了！");
		return;
	}
	layer.confirm('确认要升为超级管理员吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
            type: 'post',
            url: '<%=path %>/manager/admin/upAdmin',
            data:{id:id},
            //dataType: 'json',
            success: function(data){
		
		$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_down(this,'+id+')" href="javascript:;" title="减权" style="text-decoration:none"><i class="Hui-iconfont" id=\"black\">&#xe6ff;</i></a>');
		$("#super"+id).html("超级管理员");
		$(obj).remove();
		layer.msg('已成为超级管理员!', {icon: 6,time:1000});
		
		superCount++;
		if(superCount>4){
		
		//	val aaa = $(".Hui-iconfont").html();
			//&#xe702
			$("i[class=Hui-iconfont]").each(function(){				
				
			   		if($(this).attr("id")=="white")
				   {
				   		$(this).css("display","none");
				   }
			  });
				
		}
		if(superCount>3){
	
		//	val aaa = $(".Hui-iconfont").html();
			//&#xe702
			$("i[class=Hui-iconfont]").each(function(){				
				
			   		if($(this).attr("id")=="black")
				   {
				   		$(this).css("display","inline");
				   }
			  });
				
		}
	
            },
            
        });    
	});
}

/*管理员-减权限*/
function admin_down(obj,id){
	//alert(superCount);
	if(superCount<=2) {
		alert("不能再减 了！");
		return;
	}
	//alert(superCount);
	layer.confirm('确认要降为普通管理员吗？',function(index){
		//此处请求后台程序，下方是成功后的前台处理……
		$.ajax({
            type: 'post',
            url: '<%=path %>/manager/admin/downAdmin',
            data:{id:id},
            //dataType: 'json',
            success: function(data){
		
		$(obj).parents("tr").find(".td-manage").prepend('<a onClick="admin_up(this,'+id+')" href="javascript:;" title="加权" style="text-decoration:none"><i class="Hui-iconfont" id=\"white\">&#xe702;</i></a>');
		$("#super"+id).html("普通管理员");
		$(obj).remove();
		layer.msg('已成为普通管理员!', {icon: 6,time:1000});
		superCount--;
		
		if(superCount<=5){
			
		//	val aaa = $(".Hui-iconfont").html();
			//&#xe702
			$("i[class=Hui-iconfont]").each(function(){				
				
			   		if($(this).attr("id")=="white")
				   {
				   		$(this).css("display","inline");
				   }
			  });
				
		}
		if(superCount<3){
		
		//	val aaa = $(".Hui-iconfont").html();
			//&#xe702
			$("i[class=Hui-iconfont]").each(function(){				
				
			   		if($(this).attr("id")=="black")
				   {
				   		$(this).css("display","none");
				   }
			  });
				
		}
		
            },
            
        });    
	});
}

/*分页*/
/*当前页改变背景颜色*/
 $(function() {
	 var path = "${pageContext.request.contextPath}";
$("#page${requestScope.admins.pageNum}").css("background-color","#5a98de");
$("#page${requestScope.admins.pageNum}").css("color","#fff");

if(${pageNum}<=1){
	$("#prev").css("color","black");		//当前为第一页，字体颜色为灰色
	$("#prev").css("border","black");	//当前为第一页，边框颜色为灰色
	$("#first").css("color","black");	//当前为第一页，首页颜色为灰色
	$("#first").css("border","black");	//当前为第一页，首页边框颜色为灰色
}
if(${pageNum}>=${requestScope.admins.pages}){

	$("#next").css("color","black");		//当前为最后页，字体颜色为灰色
	$("#next").css("border","black");	//当前为最后页，边框颜色为灰色
	$("#last").css("color","black");	    //当前为最后页，尾页颜色为灰色
	$("#last").css("border","black");	//当前为最后页，尾页边框颜色为灰色
}

/*上一页，下一页*/
$("#prev").click(function(){
	if(${pageNum}<=1){
		$(this).attr("href","javaScript:void(0)");
	}else{
		$(this).attr("href",path+"/manager/admin/adminSuperList?pageNum=${pageNum-1}");
	}
});

$("#next").click(function(){
	if(${pageNum}>=${requestScope.admins.pages}){
		$(this).attr("href","javaScript:void(0)");
	}else{
		$(this).attr("href",path+"/manager/admin/adminSuperList?pageNum=${pageNum+1}");
	}
});


});

</script>

</body>
</html>